package com.wafersystems.cloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

import com.wafersystems.cloud.service.impl.DeviceService;
import com.wafersystems.cloud.service.impl.devicecontroller.modbus.ServerHandle;

import lombok.extern.slf4j.Slf4j;

@SpringBootApplication
@Slf4j
public class Application {
  @Autowired
  public DeviceService deviceService;

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  @Component
  public class BeforeStartup implements CommandLineRunner {
    @Override
    public void run(String... var) throws Exception {
      log.info("start ");
      ServerHandle serverHandle = new ServerHandle();
      serverHandle.setDeviceService(deviceService);
      new Thread(serverHandle, "Server").start();
    }
  }
}
